package com.ccs.onlinemusic.tools;


import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
    private static final String salt="1b2i3t4e";

    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }


    //第一次加密
    //模拟前端加密 传送后端
    public static String inputPassToFormPass(String inputPass){
        String str="" + salt.charAt(1)+ salt.charAt(3) + salt.charAt(5) + salt.charAt(6);
        return  md5(str);
    }

    //第二次MD5加密
    //加密前端传送来的密码

    public static String formPassToDBPass(String formPass,String salt){
        String str=""+salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) +salt.charAt(4);
        return md5(str);
    }

    //将上面两个函数合并到一起调用
    public static String inputPassToDbPass(String inputPass,String saltDB){
        String formPass=inputPassToFormPass(inputPass);
        String dbPass=formPassToDBPass(formPass,saltDB);
        return dbPass;
    }

    //结果：
    public static void main(String[] args) {
        System.out.println("第一次加密 " + inputPassToFormPass("123456"));
        System.out.println("第二次加密 " + formPassToDBPass("123456",salt));
        System.out.println("第三次加密 " + inputPassToDbPass("123456",salt));
    }


}


